home *** CD-ROM | disk | FTP | other *** search
- ;;;
- ;;; The external symbols emitted by Scheme->C have been pulverized by the
- ;;; following routines from scsc/expform.sc.
- ;;; This program is intended to run as a filter reading cat xlib/*.sch and
- ;;; writing out the list of exported C symbols which need to be made visible
- ;;; in the shared library. The supplied libscx.export is the result, it won't
- ;;; need changing unless you modify the contents of xlib.
- ;;;
-
- (module hexname (main main))
-
- ;;; This function is called to convert a name into its "lower case hex" format.
-
- (define (LCHEXNAME name)
- (if (symbol? name) (set! name (symbol->string name)))
- (do ((c '())
- (i 0 (+ 1 i))
- (new (list 1)))
- ((= i (string-length name)) (list->string (cdr new)))
- (set! c (string-ref name i))
- (cond ((char=? c #\_)
- (set-cdr! (last-pair new) (list #\_ #\_)))
- ((and (char>=? c #\A) (char<=? c #\Z))
- (set-cdr! (last-pair new)
- (list (integer->char (+ (char->integer c) 32)))))
- ((or (and (char>=? c #\a) (char<=? c #\z))
- (and (char>=? c #\0) (char<=? c #\9) (> i 0)))
- (set-cdr! (last-pair new) (list c)))
- (else
- (set-cdr! (last-pair new) (cons #\_ (char->dl c 16 2)))))))
-
- ;;; This function is one of those that you hope you never have to write, but
- ;;; inevitably you must. It exists because vcc will only recognize the first
- ;;; 31 characters of a variable name. In order to force the first 31
- ;;; characters of a generated name to be unique, it is necessary that the
- ;;; lchexnames of the module and variable be less than or equal to 28
- ;;; characters. If it doesn't fit, then a name is generated consisting of
- ;;; the last 9 characters of the module name, the last 10 characters of the
- ;;; name, and the hex crc-32 of the module and name.
-
- (define (HEX28 module name)
- (if (<= (+ (string-length module) (string-length name)) 28)
- (if (equal? module "") name (string-append module "_" name))
- (let ((value (format '() "~a_~a_~a"
- (substring module
- (max 0 (- (string-length module) 9))
- (string-length module))
- (substring name
- (max 0 (- (string-length name) 10))
- (string-length name))
- (crc-32x2 (string->list
- (string-append module name)) 0 0))))
- (if (char-numeric? (string-ref value 0))
- (string-set! value 0 #\_))
- value)))
-
- ;;; Compute a crc-32 for a list of characters using a per character table and
- ;;; return a string with the hex value. The crc is computed in two 16-bit
- ;;; integers to avoid having to use floating point numbers.
-
- (define (CRC-32x2 chars crc-left crc-right)
- (if (null? chars)
- (let loop ((cl '()) (left crc-left) (right crc-right))
- (if (and (zero? left) (zero? right))
- (if (null? cl) "0" (list->string cl))
- (loop (cons (string-ref "0123456789abcdef"
- (remainder right 16))
- cl)
- (quotient left 16)
- (+ (bit-lsh (remainder left 16) 12)
- (quotient right 16)))))
- (let ((char (char->integer (car chars))))
- (crc-32x2 (cdr chars)
- (bit-xor (bit-rsh crc-left 8)
- (vector-ref t-left char)
- (vector-ref t-left (remainder crc-right 256)))
- (bit-xor (bit-or (bit-lsh (bit-and crc-left 255) 8)
- (bit-rsh crc-right 8))
- (vector-ref t-right char)
- (vector-ref t-right (remainder crc-right 256)))))))
-
- (define T-LEFT '#(
- #x0000 #x7707 #xEE0E #x9909 #x076D #x706A #xE963 #x9E64
- #x0EDB #x79DC #xE0D5 #x97D2 #x09B6 #x7EB1 #xE7B8 #x90BF
- #x1DB7 #x6AB0 #xF3B9 #x84BE #x1ADA #x6DDD #xF4D4 #x83D3
- #x136C #x646B #xFD62 #x8A65 #x1401 #x6306 #xFA0F #x8D08
- #x3B6E #x4C69 #xD560 #xA267 #x3C03 #x4B04 #xD20D #xA50A
- #x35B5 #x42B2 #xDBBB #xACBC #x32D8 #x45DF #xDCD6 #xABD1
- #x26D9 #x51DE #xC8D7 #xBFD0 #x21B4 #x56B3 #xCFBA #xB8BD
- #x2802 #x5F05 #xC60C #xB10B #x2F6F #x5868 #xC161 #xB666
- #x76DC #x01DB #x98D2 #xEFD5 #x71B1 #x06B6 #x9FBF #xE8B8
- #x7807 #x0F00 #x9609 #xE10E #x7F6A #x086D #x9164 #xE663
- #x6B6B #x1C6C #x8565 #xF262 #x6C06 #x1B01 #x8208 #xF50F
- #x65B0 #x12B7 #x8BBE #xFCB9 #x62DD #x15DA #x8CD3 #xFBD4
- #x4DB2 #x3AB5 #xA3BC #xD4BB #x4ADF #x3DD8 #xA4D1 #xD3D6
- #x4369 #x346E #xAD67 #xDA60 #x4404 #x3303 #xAA0A #xDD0D
- #x5005 #x2702 #xBE0B #xC90C #x5768 #x206F #xB966 #xCE61
- #x5EDE #x29D9 #xB0D0 #xC7D7 #x59B3 #x2EB4 #xB7BD #xC0BA
- #xEDB8 #x9ABF #x03B6 #x74B1 #xEAD5 #x9DD2 #x04DB #x73DC
- #xE363 #x9464 #x0D6D #x7A6A #xE40E #x9309 #x0A00 #x7D07
- #xF00F #x8708 #x1E01 #x6906 #xF762 #x8065 #x196C #x6E6B
- #xFED4 #x89D3 #x10DA #x67DD #xF9B9 #x8EBE #x17B7 #x60B0
- #xD6D6 #xA1D1 #x38D8 #x4FDF #xD1BB #xA6BC #x3FB5 #x48B2
- #xD80D #xAF0A #x3603 #x4104 #xDF60 #xA867 #x316E #x4669
- #xCB61 #xBC66 #x256F #x5268 #xCC0C #xBB0B #x2202 #x5505
- #xC5BA #xB2BD #x2BB4 #x5CB3 #xC2D7 #xB5D0 #x2CD9 #x5BDE
- #x9B64 #xEC63 #x756A #x026D #x9C09 #xEB0E #x7207 #x0500
- #x95BF #xE2B8 #x7BB1 #x0CB6 #x92D2 #xE5D5 #x7CDC #x0BDB
- #x86D3 #xF1D4 #x68DD #x1FDA #x81BE #xF6B9 #x6FB0 #x18B7
- #x8808 #xFF0F #x6606 #x1101 #x8F65 #xF862 #x616B #x166C
- #xA00A #xD70D #x4E04 #x3903 #xA767 #xD060 #x4969 #x3E6E
- #xAED1 #xD9D6 #x40DF #x37D8 #xA9BC #xDEBB #x47B2 #x30B5
- #xBDBD #xCABA #x53B3 #x24B4 #xBAD0 #xCDD7 #x54DE #x23D9
- #xB366 #xC461 #x5D68 #x2A6F #xB40B #xC30C #x5A05 #x2D02
- ))
-
- (define T-RIGHT '#(
- #x0000 #x3096 #x612C #x51BA #xC419 #xF48F #xA535 #x95A3
- #x8832 #xB8A4 #xE91E #xD988 #x4C2B #x7CBD #x2D07 #x1D91
- #x1064 #x20F2 #x7148 #x41DE #xD47D #xE4EB #xB551 #x85C7
- #x9856 #xA8C0 #xF97A #xC9EC #x5C4F #x6CD9 #x3D63 #x0DF5
- #x20C8 #x105E #x41E4 #x7172 #xE4D1 #xD447 #x85FD #xB56B
- #xA8FA #x986C #xC9D6 #xF940 #x6CE3 #x5C75 #x0DCF #x3D59
- #x30AC #x003A #x5180 #x6116 #xF4B5 #xC423 #x9599 #xA50F
- #xB89E #x8808 #xD9B2 #xE924 #x7C87 #x4C11 #x1DAB #x2D3D
- #x4190 #x7106 #x20BC #x102A #x8589 #xB51F #xE4A5 #xD433
- #xC9A2 #xF934 #xA88E #x9818 #x0DBB #x3D2D #x6C97 #x5C01
- #x51F4 #x6162 #x30D8 #x004E #x95ED #xA57B #xF4C1 #xC457
- #xD9C6 #xE950 #xB8EA #x887C #x1DDF #x2D49 #x7CF3 #x4C65
- #x6158 #x51CE #x0074 #x30E2 #xA541 #x95D7 #xC46D #xF4FB
- #xE96A #xD9FC #x8846 #xB8D0 #x2D73 #x1DE5 #x4C5F #x7CC9
- #x713C #x41AA #x1010 #x2086 #xB525 #x85B3 #xD409 #xE49F
- #xF90E #xC998 #x9822 #xA8B4 #x3D17 #x0D81 #x5C3B #x6CAD
- #x8320 #xB3B6 #xE20C #xD29A #x4739 #x77AF #x2615 #x1683
- #x0B12 #x3B84 #x6A3E #x5AA8 #xCF0B #xFF9D #xAE27 #x9EB1
- #x9344 #xA3D2 #xF268 #xC2FE #x575D #x67CB #x3671 #x06E7
- #x1B76 #x2BE0 #x7A5A #x4ACC #xDF6F #xEFF9 #xBE43 #x8ED5
- #xA3E8 #x937E #xC2C4 #xF252 #x67F1 #x5767 #x06DD #x364B
- #x2BDA #x1B4C #x4AF6 #x7A60 #xEFC3 #xDF55 #x8EEF #xBE79
- #xB38C #x831A #xD2A0 #xE236 #x7795 #x4703 #x16B9 #x262F
- #x3BBE #x0B28 #x5A92 #x6A04 #xFFA7 #xCF31 #x9E8B #xAE1D
- #xC2B0 #xF226 #xA39C #x930A #x06A9 #x363F #x6785 #x5713
- #x4A82 #x7A14 #x2BAE #x1B38 #x8E9B #xBE0D #xEFB7 #xDF21
- #xD2D4 #xE242 #xB3F8 #x836E #x16CD #x265B #x77E1 #x4777
- #x5AE6 #x6A70 #x3BCA #x0B5C #x9EFF #xAE69 #xFFD3 #xCF45
- #xE278 #xD2EE #x8354 #xB3C2 #x2661 #x16F7 #x474D #x77DB
- #x6A4A #x5ADC #x0B66 #x3BF0 #xAE53 #x9EC5 #xCF7F #xFFE9
- #xF21C #xC28A #x9330 #xA3A6 #x3605 #x0693 #x5729 #x67BF
- #x7A2E #x4AB8 #x1B02 #x2B94 #xBE37 #x8EA1 #xDF1B #xEF8D
- ))
-
- ;;; This function converts the character "c" into numeric string of length
- ;;; "len" in base "base".
-
- (define (CHAR->DL c base len)
- (set! c (char->integer c))
- (do ((dl '()))
- ((zero? len) dl)
- (set! dl (cons (string-ref "0123456789abcdef" (remainder c base)) dl))
- (set! c (quotient c base))
- (set! len (- len 1))))
-
- (define (main clargs)
- (define (write-hex28 input-form)
- (define (form-is? x)
- (eq? (car input-form) x))
- (define (form-module)
- (lchexname (caddr input-form)))
- (define (form-symbol)
- (lchexname
- (if (pair? (cadr input-form))
- (caadr input-form)
- (cadr input-form))))
- (cond ((form-is? 'define-c-external) #f)
- ((form-is? 'define-constant) #f)
- ((form-is? 'define-external)
- (let ((hexname (hex28 (form-module) (form-symbol))))
- (display hexname)
- (newline)
- (display (string-append hexname "_v"))
- (newline)))
- (else
- (error 'write-hex28 "Unrecognized form: ~s" input-form))))
- (define (read-form)
- (let ((input (read)))
- (when (not (eof-object? input))
- (write-hex28 input)
- (read-form))))
- (read-form)
- (exit))
-